package com.nlscan.ncomgateway.core.manager

import android.content.Context
import com.nlscan.ble.util.NLogUtil
import com.nlscan.ncomgateway.core.newland.common.NlsVariate
import com.nlscan.ncomgateway.core.newland.common.NlsVariateHelper
import com.nlscan.ncomgateway.core.newland.entity.BroadcastOutputParams
import com.nlscan.ncomgateway.core.newland.profile.IProfileStrategy
import com.nlscan.ncomgateway.core.newland.profile.NtsProfileStrategy
import com.nlscan.ncomgateway.core.profile.AppProfileStrategy

/**
 * <pre>
 * author: lin.qing
 * time  : 2023/4/21
 * desc  :
</pre>
 */
object ProfileManager : IProfileStrategy {

    private lateinit var strategy: IProfileStrategy

    fun init(context: Context) {
        NlsVariateHelper.initNtsParam(context)
        val support = NlsVariate.supportNts
        strategy = if (support) {
            NtsProfileStrategy
        } else {
            AppProfileStrategy
        }
        NLogUtil.i("init supportNts: $support")
    }

    fun isSupportNts() = NlsVariate.supportNts

    fun getProfileName() = NlsVariate.profileName

    override fun updateSettings(): HashMap<String, String?>? {
        return strategy.updateSettings()
    }

    override fun getOutputMode(): Int {
        return strategy.getOutputMode()
    }

    override fun setOutputMode(mode: Int) {
        return strategy.setOutputMode(mode)
    }

    // TODO: 待处理
    override fun getBroadcastOutputAction(): String {
        return strategy.getBroadcastOutputAction()
    }

    // TODO: 待处理
    override fun getBroadcastOutputExtraResult(): String {
        return strategy.getBroadcastOutputExtraResult()
    }

    // TODO: 临时适配  当前临时手动填充sp值
    override fun getBroadcastOutputParams(): BroadcastOutputParams {
        val params = strategy.getBroadcastOutputParams()
        if (isSupportNts()) {
            // 临时手动填充sp值
            val localParams = AppProfileStrategy.getBroadcastOutputParams()
            params.exScannerAction = localParams.exScannerAction
            params.exScannerExtraBarcode = localParams.exScannerExtraBarcode
            params.exScannerExtraDeviceName = localParams.exScannerExtraDeviceName
            params.exScannerExtraAddress = localParams.exScannerExtraAddress
            params.exScannerExtraSerialNumber = localParams.exScannerExtraSerialNumber
            params.exScannerExtraBarcodeType = localParams.exScannerExtraBarcodeType
            params.exScannerExtraBarcodeTypeName = localParams.exScannerExtraBarcodeTypeName
        }
        return params
    }

    override fun setBroadcastOutputParams(params: BroadcastOutputParams) {
        return strategy.setBroadcastOutputParams(params)
    }

    override fun setIndicateSoundEnable(enable: Boolean): Boolean {
        return strategy.setIndicateSoundEnable(enable)
    }

    override fun getIndicateVibrateEnable(): Boolean {
        return strategy.getIndicateVibrateEnable()
    }

    override fun setIndicateVibrateEnable(enable: Boolean): Boolean {
        return strategy.setIndicateVibrateEnable(enable)
    }

    override fun getIndicateLedEnable(): Boolean {
        return strategy.getIndicateLedEnable()
    }

    override fun setIndicateLedEnable(enable: Boolean): Boolean {
        return strategy.setIndicateLedEnable(enable)
    }

    override fun getPrefix(): String {
        return strategy.getPrefix()
    }

    override fun getPrefixEnable(): Boolean {
        return strategy.getPrefixEnable()
    }

    override fun setPrefixParams(value: String, enable: Boolean): Boolean {
        return strategy.setPrefixParams(value, enable)
    }

    override fun getSuffix(): String {
        return strategy.getSuffix()
    }

    override fun getSuffixEnable(): Boolean {
        return strategy.getSuffixEnable()
    }

    override fun setSuffixParams(value: String, enable: Boolean): Boolean {
        return strategy.setSuffixParams(value, enable)
    }


}